#include <iostream>
#include <string>
#include <cstdlib>
#include <fstream>
#include "../Utils/directoryHandler.h"
#include "../Utils/index.h"
#include "monitor.h"
#include <gtkmm/main.h>
#include "monitor_first.h"
using namespace std;

#define LOGFILE "Monitor.log"

log4cpp::Appender *appender = new log4cpp::FileAppender("FileAppender",
		LOGFILE);
log4cpp::Layout *layout = new log4cpp::SimpleLayout();
log4cpp::Category& category = log4cpp::Category::getInstance("Category");

int main(int argc, char** argv) {
	appender->setLayout(layout);
	category.setAppender(appender);
	category.setPriority(log4cpp::Priority::INFO);
	string userFolder(getenv("HOME"));
	//Obtengo fecha y hora
	time_t rawtime;
	time(&rawtime);
	struct tm * timeinfo = localtime(&rawtime);
	time_t tim = time(NULL);
	tm *now = localtime(&tim);
	category.info("New monitor log started at %02d:%02d of %02d/%02d/%d",
			now->tm_hour, now->tm_min, now->tm_mday, now->tm_mon + 1,
			now->tm_year + 1900);

	category.info("User folder is: " + userFolder);
	string properties_file_name("cfg.properties");
	category.info("Server cfg file name is: " + properties_file_name);

	Monitor m(userFolder, properties_file_name);
	m.InitializeCfg();
	m.InitializeAccounts();
	Gtk::Main kit(argc, argv);
	First first(&m);
	Gtk::Main::run(first);
	m.SaveNewConfiguration();
	m.SaveNewAccountsFile();

	return 0;
}

